//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<XAppDesktop.h>
///	@path	~/src/appear/xwin/
///	@date	2008/09/07
///	@desc	.

#include "xeres.h"

#include "graphics/IEffect.h"
#include "graphics/ITechnique.h"
#include "graphics/IShaderVariable.h"
#include "graphics/ITexture.h"
#include "graphics/IRenderTarget.h"

#include "gui/image/ImageResource.h"
#include "gui/composite/CCompositeTexture.h"
#include "gui/xgui/XDesktop.h"

#include "appear/xwin/FrameComposition.h"

namespace xeres {

	// forward declaration
	class IGuiEffect;
	class XAppPopup;

	/*! 
		\class	XAppDesktop
		\brief	Application desktop for DX rendering.
	*/
	class XAppDesktop : public XDesktop , public FrameComposition
	{
	public:

		/// \ctor
		XAppDesktop( ImageResource * img_res );

		/// \dtor
		virtual ~XAppDesktop( void );

		DECL_IOBJECT_CLASS( XAppDesktop , XDesktop );

	public:

		/// \brief	Redraw all.
		void RedrawAll( void );

		/// \brief	Attach effect of window.
		bool AttachEffect( RefWeak<XFrame> frame , Ref<IGuiEffect> effect );

		/// \name Desktop Attributes
		//@{

		/// \brief	Attach frame.
		virtual void Attach( RefWeak<XFrame> frame );

		/// \brief	Detach form.
		virtual void Detach( RefWeak<XFrame> frame );

		/// \brief	Set desktop size.
		void SetAppDesktopSize( RenderContext& rc , const Pair<int>& size );

		//@}

		/// \name Window Management
		//@{

		/// \brief	Show window.
		virtual void ShowWindow( RefWeak<XFrame> frame , bool show , bool animate );

		/// \brief	Pin window to top.
		virtual void PinWindow( RefWeak<XFrame> frame , bool pin );

		/// \brief	Track tips.
		virtual void TrackTips( RefWeak<IGuiComp> comp , const WString& tips );

		/// \brief	Clear tips.
		virtual void ClearTips( void );

		//@}

		/// \name Presentation Manipulation
		//@{

		///	\brief	Process mouse input message.
		virtual HandleInput OnMouseInput( Updater& updater );

		///	\brief	Process key input message.
		virtual HandleInput OnKeyInput( Updater& updater );

		/// \brief	Tick update.
		virtual void Tick( Updater& updater , float dTime );

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( Composition& composition );

		/// \brief	Draw XGUI component to composition.
		virtual void Draw( RenderContext& rc );

		/// \brief	Draw background.
		virtual void OnDrawBackground( Composition& composition );

		/// \brief	Clear focus.
		virtual void ClearFocus( Updater& updater );

		/// \brief	Request focus.
		virtual void RequestFocus( RefWeak<IGuiComp> comp , Updater& updater );

		/// \brief	Request update.
		virtual void RequestUpdate( RefWeak<IGuiComp> comp , const Rect<int>& region );

		/// \brief	Request show frame.
		virtual void RequestShow( RefWeak<XFrame> frame , bool show );

		//@}

	private:

		/// \brief	Show window callback after effect.
		void ShowWindowAfterEffect( RefWeak<XFrame> frame , bool show );

		//@ data

		ImageResource *					m_imageResource;

		// hidden frames
		std::set< RefWeak<XFrame> >		m_hidden;

		Ref<XAppPopup>					m_tips;

		// cursor position cache
		Pair<int>						m_cursor;

		// hover test.
		float							m_hoverTime;
	};

} // namespace xeres
